﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;

namespace GPCSC.Web.WBWZ
{
    public partial class newlists : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    buildTZGG();
                    buildGZJB();
                    string value = Usual.f_querystringToString("value");
                    if (value != null && value != "")
                    {
                        if (value == "6")//民情日记
                        {
                            buildmq();
                        }
                        else
                        {
                            buildlist(value);
                        }
                        this.menuid.Value = value;

                        //switch (value)
                        //{ 
                        //    case "1":
                        //        Label1.Text = "通知公告列表";
                        //        break;
                        //    case"2":
                        //        Label1.Text = "工作动态列表";
                        //        break;
                        //    case "3":
                        //        Label1.Text = "经验交流列表";
                        //        break;
                        //    case "4":
                        //        Label1.Text = "调研报告列表";
                        //        break;
                        //    case"5":
                        //        Label1.Text = "工作简报列表";
                        //        break;
                        //    case "6":
                        //        Label1.Text = "民情日记列表";
                        //        break;
                        //}

                    }
                }
                catch (Exception ee)
                {
                    throw ee;
                }
            }
        }
        /// <summary>
        /// 绑定民情日记
        /// </summary>
        protected void buildmq()
        {
            Hashtable htable = new Hashtable();
            DataSet ds = new DataReturn().ReturnData(htable, "sel_mqlists_all");
            if (ds != null)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    dr["NewsID"] = dr["tabids"].ToString();
                    //dr["NewsTitles"] = dr["mqdate"].ToString() + " " + dr["lgname"].ToString() + "民情日记";
                    dr["NewsTitles"] = dr["mqtitle"].ToString(); 
                    dr["showtitle"] = dr["mqtitle"].ToString(); 
                    dr["FBdate"] = Usual.f_convertDateTime(dr["mqdate"].ToString()).ToShortDateString();
                    dr["BTSBLMName"] = "6";
                }
                newslist.DataSource = ds;
                newslist.DataBind();
                this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], newslist, 15);
            }
        }
        /// <summary>
        /// 绑定页面列表
        /// </summary>
        /// <param name="id">栏目值</param>
        protected void buildlist(string id)
        {
            Hashtable htable = new Hashtable();
            htable.Add("BTSBLMName",id);
            DataSet ds = new DataReturn().ReturnData(htable, "sel_newlists_all");
            if (ds != null)
            {
                newslist.DataSource =ds;
                newslist.DataBind();
                this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], newslist, 15);
            }
        }

        //绑定工作动态
        protected void buildTZGG()
        {
            Hashtable htable = new Hashtable();

            htable.Add("BTSBLMName", "2");
            DataSet ds = new DataReturn().ReturnData(htable, "sel_sydtxw_all");
            if (ds != null)
            {

                tzgg.DataSource = cutTitle(ds);
                tzgg.DataBind();
            }
        }


        //绑定工作简报
        protected void buildGZJB()
        {
            //Hashtable htable = new Hashtable();

            //htable.Add("BTSBLMName", "5");
            //DataSet ds = new DataReturn().ReturnData(htable, "sel_sydtxw_all");
            //if (ds != null)
            //{

            //    gzjb.DataSource = cutTitle(ds);
            //    gzjb.DataBind();
            //}
            //buildmq();
            Hashtable htable = new Hashtable();
            DataSet ds = new DataReturn().ReturnData(htable, "sel_mqlists_to");
            if (ds != null)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    dr["NewsID"] = dr["tabids"].ToString();
                    dr["NewsTitles"] = dr["mqtitle"].ToString();
                    //if (dr["mqtitle"].ToString().Length > 18)
                    //{
                    //    dr["showtitle"] = dr["mqtitle"].ToString().Substring(0, 18) + "...";
                    //}
                    //else
                    //{
                    //    dr["showtitle"] = dr["mqtitle"].ToString();
                    //}
                    dr["showtitle"] = dr["mqdate"].ToString() + " " + dr["lgname"].ToString() + "民情日记";
                    dr["FBdate"] = Usual.f_convertDateTime(dr["mqdate"].ToString()).ToShortDateString();
                    dr["BTSBLMName"] = "6";
                }
                gzjb.DataSource = ds;
                gzjb.DataBind();
            }
        }


        /// <summary>
        /// 若标题过长  截取标题
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        protected DataSet cutTitle(DataSet ds)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (dr["NewsTitles"].ToString().Length > 18)
                    {
                        dr["showtitle"] = dr["NewsTitles"].ToString().Substring(0, 18) + "...";
                    }
                    else
                    {
                        dr["showtitle"] = dr["NewsTitles"].ToString();
                    }
                }
            }
            return ds;
        }


    }
}